package net.caixiaomi.info.adapter;

import android.support.annotation.LayoutRes;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.RelativeLayout;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.model.MessageItem;

/**
 * 通知
 */

public class NoticeAdapter extends BaseQuickAdapter<MessageItem, BaseViewHolder> {

    public NoticeAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MessageItem item) {
        try {
            StringBuilder stringBuilder = new StringBuilder();
            String[] split = item.getMsgDesc().split("#");
            for (String text : split) {
                stringBuilder.append(text).append("\n");
            }
            if (stringBuilder.length() > 0) {
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            }
            helper.setText(R.id.title, item.getTitle());
            helper.setText(R.id.time, item.getSendTime());
            helper.setText(R.id.summary, item.getContent());
            helper.setText(R.id.content, stringBuilder);
            helper.setText(R.id.status, item.getContentDesc());
            helper.setGone(R.id.status, !TextUtils.isEmpty(item.getContentDesc()));

            RelativeLayout.LayoutParams reLlayoutParams = (RelativeLayout.LayoutParams) helper.getView(R.id.btn_look).getLayoutParams();
            reLlayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, !TextUtils.isEmpty(item.getContentDesc()) ? R.id.status : R.id.content);

            helper.addOnClickListener(R.id.btn_look);
            if (helper.getAdapterPosition() == 0) {
                RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) helper.itemView.getLayoutParams();
                layoutParams.topMargin = (int) CommonApp.getInstance().getResources().getDimension(net.caixiaomi.info.R.dimen.padding_12);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
